<template>
  <el-container class="layout-container-demo">
    <!-- 左侧侧边栏 -->
    <el-aside width="200px">
      <el-scrollbar>
        <el-menu :default-openeds="['1']" default-active="1-5" unique-opened @select="handleMenuSelect">
          <el-sub-menu index="1">
            <template #title>
              <el-icon><message /></el-icon>
              患者管理
            </template>
            <el-menu-item index="1-4">患者列表</el-menu-item>
            <!-- <el-menu-item index="2-5">地图</el-menu-item> -->
          </el-sub-menu>
          <!-- 医院信息管理 -->
          <el-sub-menu index="2">
            <template #title>
              <el-icon><message /></el-icon>
              医院信息管理
            </template>
            <el-menu-item index="2-4">医院管理</el-menu-item>
            <el-menu-item index="2-5">医生管理</el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="3">
            <template #title>
              <el-icon><message /></el-icon>
              患教信息管理
            </template>
            <el-menu-item index="3-4">患教活动管理</el-menu-item>
            <!-- <el-menu-item index="3-5">查看患教活动</el-menu-item> -->
          </el-sub-menu>
          <el-sub-menu index="4">
            <template #title>
              <el-icon><message /></el-icon>
              病例探讨管理
            </template>
            <el-menu-item index="4-4">病例探讨</el-menu-item>
            <!-- <el-menu-item index="4-5">医生管理</el-menu-item> -->
          </el-sub-menu>
          <!-- 其他菜单项 -->
        </el-menu>
      </el-scrollbar>
    </el-aside>
    <!-- 右侧内容区域 -->
    <el-container>
      <!-- 顶部工具栏 -->
      <el-header class="top-header">
        <div class="toolbar">
          <!-- <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px;"><setting /></el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>View</el-dropdown-item>
                <el-dropdown-item>Add</el-dropdown-item>
                <el-dropdown-item>Delete</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown> -->
          <div class="tou">
            <span>{{username}}</span>
            <button @click="logout">退出</button>
          </div>
        </div>
      </el-header>
      
      <!-- 路由视图 -->
      <router-view />

        
     
      
    </el-container>
  </el-container>
</template>

<script lang="ts">
import { Menu as IconMenu, Message, Setting } from '@element-plus/icons-vue'
import { User } from '@element-plus/icons-vue';
import { ref } from 'vue';
import { useRouter } from 'vue-router';

export default {
  setup() {
    const router = useRouter();

    const user = JSON.parse(localStorage.getItem('sysuser') as string)
    console.log(localStorage.getItem('sysuser'))
    console.log(user.name)
    const username = user.name
    const handleMenuSelect = (index) => {
      if(index==1){
        router.push('/index/doctor');
      }
      if (index === '2-5') {
        router.push('/index/doctor');
      }
      if (index === '1-4') {
        router.push('/index/patient');
      }
      if (index === '2-4') {
        router.push('/index/depinfo');
      }
      if (index === '3-4') {
        router.push('/index/patientEduManage');
      }
      if(index === '3-5'){
        router.push('/index/patienEduQuery');
      }
      if(index === '4-4'){
        router.push('/index/casted');
      }
    };

    const logout = () => {
      router.push('login').then(() => {
    window.location.reload();
  });
      console.log('用户已退出');
    };

    return {
      handleMenuSelect,
      logout,
      username
    };
  }
  
};
</script>

<style scoped>
.tou {
  display: flex;
  margin-left : 1250px;
  align-items: right;
}
.layout-container-demo {
  height: 100vh;
  display: flex;
  flex-direction: row;
}

.el-aside {
  color: var(--el-text-color-primary);
  background: var(--el-color-primary-light-8);
}

.el-menu {
  border-right: none;
}

.top-header {
  display: flex;
  /* justify-content: space-between; */
  align-items: right;
  background-color: var(--el-color-primary-light-9);
  padding: 0 20px;
}

.toolbar {
  display: flex;
  align-items: center;
}

.toolbar span {
  margin-right: 20px;
}
</style>
